package com.foton.designmodel.decorator.impl;

import com.foton.designmodel.decorator.orderprice.entity.Order;
import com.foton.designmodel.strategy.StrategyFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Random;

/**
 * 会员折扣价 会员再减5块
 */
@Slf4j
@Component("vipPriceSum")
public class VipPriceSum extends DecoratorMoneySum {


    @Resource
    private StrategyFactory strategyFactory;


    @Override
    public Order money(Order order) {
        super.money(order);
        vipSum(order);
        return order;
    }


    // 会员折扣价 会员再减5块
    private void vipSum(Order order) {
        log.info("会员优惠方法执行；；；；；");
        int level = new Random().nextInt(4);
        Integer money = strategyFactory.getExecuteInstance(level)
                .money(order.getAcutMoney());
        order.setAcutMoney(money);
        log.info("订单参加【VIP优惠】的结算金额 {}", order);
    }
}
